<?php

namespace App\Admin\Controllers;

use App\Models\Customer;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class CustomerController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = '客服管理';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Customer);
        $grid->column('id', __('Id'));
        $grid->column('number', __('qq号'));
        $grid->column('status', __('状态'))->display(function ($status) {
            return config('conf.status')[$status];
        });
        $grid->column('created_at', __('创建时间'));
        $grid->column('updated_at', __('修改时间'));
//        $grid->disableCreateButton();
//        $grid->actions(function ($actions) {
//            $actions->disableDelete();
//            $actions->disableView();
//        });
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Customer::findOrFail($id));

        $show->field('id', __('Id'));
        $show->field('number', __('number'));
        $show->field('status', __('Status'))->display(function ($status) {
            return config('conf.coin_status')[$status];
        });
        $show->field('created_at', __('Created at'));
        $show->field('updated_at', __('Updated at'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Customer);

        $form->text('number', __('qq号'));
        $form->select('status', __('状态'))->options(config('conf.status'));
       // $form->text('reason', __('驳回原因'));
//        $form->saving(function (Form $form) {
//            if($form->status==2){
//                User::where('id',$form->user_id)->increment('btc',$form->btc);
//                (new UserLog())->change($form->btc,$form->user_id,'btc',44,'提币退回');
//            }
//        });
        return $form;
    }
}
